package com.bluetrum.abmate.log;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.bluetrum.ablogger.ABLogger;
import com.bluetrum.ablogger.LogEvent;

import java.util.List;

import timber.log.Timber;

/**
 * ABLogger套壳，并接入FOTA的log
 */
public class AppLogger {

    public static void setupLogger(@NonNull Context context) {
        // 配置DeviceManager的Log接口
        com.bluetrum.devicemanager.log.Logger.setLogger(deviceManagerLogger);
        // 配置FOTA的Log接口
        com.bluetrum.fota.log.Logger.setLogger(fotaLogger);

        ABLogger.setupLogger(context);
    }

    /**
     * 使用Log.VERBOSE，默认是Log.INFO
     */
    public static void enableVerboseMode() {
//        com.bluetrum.fota.log.Logger.setLogLevel(Log.VERBOSE);
        ABLogger.setLogLevel(Log.VERBOSE);
    }

    public static List<LogEvent> getLogEventList() {
        return ABLogger.getLogEventList();
    }

    public static void clearLogEventList() {
        ABLogger.getLogEventList().clear();
    }

    private static final com.bluetrum.devicemanager.log.ILogger deviceManagerLogger = (logLevel, tag, message, t) -> {
        if (tag == null) {
            Timber.log(logLevel, message, t);
        } else {
            Timber.tag(tag).log(logLevel, message, t);
        }
    };

    private static final com.bluetrum.fota.log.ILogger fotaLogger = (logLevel, tag, message, t) -> {
        if (tag == null) {
            Timber.log(logLevel, message, t);
        } else {
            Timber.tag(tag).log(logLevel, message, t);
        }
    };
}
